/*
 * Copyright 2007 - The JDPF Project Team (http://www.jdpf.org) 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */
package org.jdpf.core.kernel.logging;

import java.util.Date;

public class LoggerFactory implements ILogger {

	private static IBasicLogger logger = new DefaultLogger();

	public ILogger getLogger() {
		return this;
	}

	public static LoggerFactory getDefault() {
		return new LoggerFactory();
	}

	public void forceToDefaultLogger() {
		LoggerFactory.logger = new DefaultLogger();
	}

	public void setLogger(IBasicLogger logger) {
		LoggerFactory.logger = logger;
	}

	protected LoggerFactory() {
		// Empy constructor. It's private so users cannot instance a
		// LoggerFactory object
	}

	public void error(String text) {
		logger.error(date() + "EXCEPTION - " + text);
	}
	
	public void error(Object o, String text) {
		logger.error(date() + "EXCEPTION - [" + o.getClass().getSimpleName()  + "] " + text);
	}
	
	public void error(Object o, String pluginId, String text) {
		logger.error(date() + "EXCEPTION - [" + o.getClass().getSimpleName() + " - " + pluginId + "] " + text);
	}
	
	public void error(Object o, String pluginId, String id, String text) {
		logger.error(date() + "EXCEPTION - [" + o.getClass().getSimpleName() + " - " + pluginId + " - " + id + "] " + text);
	}
	
	public void warning(Object o, String pluginId, String id, String text) {
		logger.error(date() + "WARNING - [" + o.getClass().getSimpleName() + " - " + pluginId + " - " + id + "] " + text);
	}

	public void fatal(String text) {
		logger.fatal(date() + text);
	}
	
	public void fatal(Object o, String text) {
		logger.fatal(date() + "[" + o.getClass().getSimpleName()  + "] " + text);
	}

	public void fatal(Object o, String pluginId, String id, String text) {
		logger.fatal(date() + "[" + o.getClass().getSimpleName() + " - " + pluginId + " - " + id + "] " + text);
	}
	
	public void log(String text) {
		logger.log(date() + text);
	}

	public void log(Object o, String text) {
		logger.log(date() + "[" + o.getClass().getSimpleName() + "] " + text);
	}

	public void log(Object o, String pluginId, String text) {
		logger.log(date() + "[" + o.getClass().getSimpleName() + " - " + pluginId + "] " + text);
	}
	
	public void log(Object o, String pluginId, String id, String text) {
		logger.log(date() + "[" + o.getClass().getSimpleName() + " - " + pluginId + " - " + id + "] " + text);
	}
	
	public void log(Object o) {
		logger.log(date() + o);
	}
	
	public void logMainPoint(Object o, String pluginId, String text) {
		logger.log(date() + "##" + text + "## [" + o.getClass().getSimpleName() + " - " + pluginId + "]");
	}
	
	public void logMainPoint(Object o, String pluginId, String id, String text) {
		logger.log(date() + "##" + text + "## [" + o.getClass().getSimpleName() + " - " + pluginId + " - " + id + "]");
	}
	
	private String date(){
		return new Date(System.currentTimeMillis()).toString()+" - ";
	}

}
